/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __GAME_OBJECT_SERIALIZER_H__
#define __GAME_OBJECT_SERIALIZER_H__

#include "GameObject.h"

#include "ColliderComponent.h"
#include "ScriptComponent.h"

#include "DataSerializer.h"

using namespace PQCore;

namespace PQEngine
{
	//Warning:A single byte change may collapse the whole data format
	//The data format is unsafe.
	class GameObjectSerializer
	{
	private:
		GameObject* _root;
		SerializeDatagram* _datagram;
		SerializeGenerator* _generator;
		SerializeParser* _parser;

		void serializeGameObject(GameObject* object);
		void serializeScriptComponent(ScriptComponent* component);
		void serializeTransformComponent(TransformComponent* component);
		void serializeEntityComponent(MeshComponent* component);

		//physics
		void serializeRigidBodyComponent(RigidBodyComponent* component);
		void serializePlaneColliderComponent(PlaneColliderComponent* component);
		void serializeBoxColliderComponent(BoxColliderComponent* component);
		void serializeSphereColliderComponent(SphereColliderComponent* component);

		GameObject* parseGameObject();
		Component* parseComponent();
		Component* parseTransformComponent();
		Component* parseMeshComponent();
		Component* parseScriptComponent();
		Component* parseRigidBodyComponent();
		Component* parsePlaneColliderComponent();
		Component* parseBoxColliderComponent();
		Component* parseSphereColliderComponent();

	protected:
		GameObjectSerializer();
	public:
		static GameObjectSerializer& getSingleton();
		SerializeDatagram* serialize();
		void unserializer(SerializeDatagram* dgram);
		
	};
}
#endif
